/***	
* date：2018.03.06
* name: 产品详情页-商品输入到购物车
* author：hj
* remarks：null
*/
function enterShoppingCar(_config){
	for(var i in _config){
		this[i] = _config[i];
	}
	this.goodsnumber = '';
	this.init();
}
enterShoppingCar.prototype= {
	init:function(){
		var _self = this;
		_self.getData();
		_self.addBtn();
		_self.reduceBtn();
	},
	getData:function(){
		var _self = this;
		ajaxFn(APILIST.goodsCarNum,function(_d){	
			// 赋值
			_self.goodsnumber = _d.goodsnum;
			// 传入json参数
			_self.goodsNums( _self.goodsnumber );
		});
		_self.toCarEvent();
	},
	// 赋值到goodsNumId
	goodsNums:function(_v){
		var _self = this;
		_self.goodsNumId.attr('value',_v);
	},

	addBtn:function(){
		var _self = this;
		// 点击"+"增加数量
		_self.addBtnId.on('click',function(){
			// 获取点击"+"按钮后的数据
		getAjaxFn(APILIST.goodsCarNum,{'ops':'add'},function(_d){
			console.log(_d)
			_self.goodsNumId.attr('value',_d.goodsnum);
			});
		});
	},

	reduceBtn:function(_d){
		var _self = this;
		// 点击"-"减少数量
		_self.reduceBtnId.on('click',function(){
			// 获取点击"-"按钮后的数据
		getAjaxFn(APILIST.goodsCarNum,{'ops':'reduce'},function(_d){
			console.log(_d)
			_self.goodsNumId.attr('value',_d.goodsnum);
			});	
		});
	},
	toCarEvent:function(){
		var _self = this;
		_self.numToCarBtnId.on('click',function(){
			console.log(location.href);
			location.href = 'http://localhost:4567/cart.html'
		});
	}

}


new enterShoppingCar({
	goodsNumId:$('#goodsNumId'),
	addBtnId:$('#addBtnId'),
	reduceBtnId:$('#reduceBtnId'),
	numToCarBtnId:$('#numToCarBtnId')
});